<?php
/**
 * Date: 2018/2/5
 * Time: 11:31
 * Author: zeronlee
 */

namespace App\Models\User;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class UserExt extends Model
{

    use softDeletes;

    protected $table = 'user_ext';

    public $timestamps = true;

    protected $guarded = [];

    protected $fillable = ['user_id','alias'];

    protected $dates = ['delete_at'];

    /**
     * 插入记录
     * @param mixed $request
     * @return bool
     * @throws \Exception
     */
    public function insertRow($request){

        if ($this->save($request->input())) {


            return true;
        }

        throw new \Exception('添加失败');

    }
    /**
     * 修改记录
     * @param mixed $request
     * @return bool
     * @throws \Exception
     */
    public function updateRow($request){

        $update = $this->find($request->id);

        if($update->update($request->input())){

            return true;
        }
        throw new \Exception('更新失败');
    }
    /**
     * 基础信息
     * @param mixed $request
     * @return mixed
     * @throws \Exception
     */
    public function get($request){

        $where = ['user_id'=>$request->id];

        $ext = $this->where($where)->get();

        if(!$ext->isEmpty()){

            return $ext;
        }

        throw new \Exception('暂无信息');
    }
}